{include_core file="m/lib/header.html" title="提交订单"}
<div class="submit-order-page js_orderTradeGroup" data-invoice_type="{$invoice_type}" data-invoice_title="{$invoice_title}" data-edit-paytype="{if $pay_type}0{else}1{/if}" data-edit-address="{if $address_info}0{else}1{/if}" data-address_id="{$address_info.id}" data-pay_type="{if $pay_type}{$pay_type}{else}1{/if}" data-express_id="{$express_id}" data-express_error="{$express_error}" data-invoice_title="{$invoice_title}">
  <div class="item item1 js_openLink" data-href="{AnUrl("address/slt_address?use_id={$address_info.id}&sku_id={$direct_sku_info.id}&num={$direct_buy_num}")}">
    <a href="javascript:;" class="arrow-right"></a>
    {if $address_info}
    <p>{$address_info.province} {$address_info.city} {$address_info.district}</p>
    <p>{$address_info.address}</p>
    <p>{$address_info.receiver} {$address_info.mobile}</p>
    {else}
    <p>您还没有收获地址</p>
    <p>点击快速添加收获地址</p>
    {/if}
  </div>
  <!--订单 begin-->
  <script type="text/javascript">
    s.products="";
  </script>
  <div id="order_detail">
    {foreach $cart_list as $k=>$v}
    {$property_info = goods_helper::get_sku_property_value($v.sku_id)}
    <div class="order_top clearfix">
      <span class="img-box"><img src="{_image($v.goods_cover)}" width="130"></span>
      <div class="infor">
        <h3>{if $v.is_gift > 0}<i class="red-icon">赠品</i>{elseif $v.is_promotion > 0}<i class="red-icon">加购价</i>{/if}<a href="javascript:void(0);">{$v.goods_title}</a></h3>
        <p class="price"><span>编号：{$v.goods_id}</span></p>
        <p class="price"><span>价格：<a href="javascript:void(0);">￥{$v.goods_price}</a></span></p>
        <p class="price"><span>数量：{$v.goods_num}</span></p>
      </div>
    </div>
    <script type="text/javascript">
      s.products+=";{$v.goods_id},";
    </script>
    {/foreach}
    <div class="order_bom clearfix">
      {* <span class="order_name">配送方式：</span> *}
      <span class="order_val">快递：免运费</span>
    </div>
  </div>
  <!--订单 end-->
  <div class="item item2 order_item2">
    {* <dl data-pay_type="{$pay_type}" class="js_payTypeList">
      <dt><span class="name">支付方式</span><span class="con js_payTitle">{if $pay_type}{openapi_config::$pay_type[$pay_type]['title']}{else}支付宝{/if}支付</span><a href="javascript:" class="arrow-down"></a></dt>
      {$pay_type_list = openapi_config::$pay_type}
      {foreach $pay_type_list as $k => $v}
      <dd class="js_payType" data-pay_type="{$k}" data-pay_title="{$v.title}"><label><input type="radio" name="pay_type" {if $k == $pay_type || ($k == 1 && !$pay_type)}checked{/if}/><i></i></label><span class="tit">{$v.title}支付</span></dd>
      {/foreach}
    </dl> *}
    {*
    <dl class="js_expressTypeList" data-express_id="{$express_id}" data-express_title="{$express_title}">
      <dt><span class="name">配送方式</span><span class="con"><em class="js_expressTitle">顺丰快递</em>(<em class="js_expressSltInfo">运费：0元</em>)</span><a href="javascript:" class="arrow-down"></a></dt>
      {foreach $express_list as $k=>$v}
        <dd class="js_expressType" data-express_id="{$v.id}" data-express_title="{$v.title}"><label><input name="express_type" type="radio" {if $v.id == $express_id}checked{/if}/><i></i></label><span class="tit">{$v.title}</span><span class="explain"></span></dd>
      {/foreach}
    </dl>
    *}
    <dl class="js_invoiceList">
      <dt><span class="name">发票信息</span><span class="con js_invoiceTitle">{if $invoice_type == 1}电子发票{elseif $invoice_type == 2}增值税普通发票{else}不开发票{/if}</span><a href="javascript:" class="arrow-down"></a></dt>
      {* <dd data-invoice_type="0" data-invoice_title="不开发票">
        <label><input name="invoice" type="radio" {if !$invoice_type}checked{/if} /><i></i></label><span class="tit">不开发票</span>
      </dd> *}
      <dd data-invoice_type="1" data-invoice_title="电子发票">
        <label><input name="invoice" type="radio" {if $invoice_type == 1}checked{/if}/><i></i></label><span class="tit">电子发票</span>
      </dd>
      <dd data-invoice_type="2" data-invoice_title="增值税普通发票">
        <label><input name="invoice" type="radio" {if $invoice_type == 2}checked{/if}/><i></i></label><span class="tit">增值税普通发票</span>
        <span class="txt js_invoiceInfo" {if $invoice_type != 2}style="display:none"{/if}><input type="text" class="js_invoiceTitleInp" value="{$invoice_title}" placeholder="发票抬头"/></span>
      </dd>
    </dl>
  </div>
  <div class="item item3 order_item2">
    <dl>
      <dt><span class="name">优惠劵</span><span class="con js_viewCoupon">暂无优惠券</span><a href="javascript:" class="arrow-down"></a></dt>
      <dd><span class="cap-txt"><input type="text" class="js_couponCode" value="" placeholder="填写已有优惠码"/></span></dd>
    </dl>
  </div>
  {* <script type="text/javascript">
    s.products="";
  </script>
  <div class="item item4">
    <dl>
      <dt><span>商品清单：共{$cart_num}件商品</span><a href="javascript:" class="arrow-down"></a></dt>
      <dd>
        <ul class="list">
          {foreach $cart_list as $k=>$v}
          {$property_info = goods_helper::get_sku_property_value($v.sku_id)}
          <li class="clearfix">
            <span class="img-box"><img src="{_image($v.goods_cover)}" width="91" height="91"></span>
            <div class="infor">
              <h3>{if $v.is_gift > 0}<i class="red-icon">赠品</i>{elseif $v.is_promotion > 0}<i class="red-icon">加购价</i>{/if}<a href="javascript:;">{$v.goods_title} {$property_info}</a></h3>
              {if $v.gift_detail}
              {foreach $v.gift_detail as $g_k=>$g_v}
              <p class="price gift">赠品：{$g_v.goods_title} x <em>{$g_v.goods_num}</em></p>
              {/foreach}
              {/if}
              <p class="price"><span>售价：{$v.goods_price}元</span><span>数量：{$v.goods_num}</span><span>小计：{if $v.is_gift >0}0.00{else}{number_format($v.goods_num*$v.goods_price, 2)}{/if}元</span></p>
            </div>
          </li>
          <script type="text/javascript">
          s.products+=";{$v.goods_id},";
          </script>
          {/foreach}
        </ul>
      </dd>
    </dl>
  </div> *}
  <div class="item item5 order_item5">
    <p><span class="order_left">合计：</span><span class="order_right js_goodsTotalPrice" data-total_price="{$total_price_format}">{$total_price_format}元</span></p>
    <p><span class="order_left">优惠：</span><span class="order_right js_couponSubPrice">0元</span></p>
    <p class="font-red"><span class="order_left">应付：</span><span class="order_right js_orderCountPrice" data-order_price="{$total_price_discount_format}">{$total_price_discount_format}元</span></p>
    {* {if is_weixin()}
    <div class="order_btns order1_btns js_subOrder" data-pay_type="2" id="baiduTjBtnWxPay"><a href="javascript:void(0);">微信付款</a></div>
    {/if} *}
    <div class="order_btns order2_btns js_subOrder" data-pay_type="1" id="baiduTjBtnAlPay"><a href="javascript:void(0);">支付宝付款</a></div>
  </div>


  {* <div class="item item5">
    <p><span class="left">商品金额合计</span><span class="right js_goodsTotalPrice" data-total_price="{$total_price_format}">{$total_price_format}元</span></p>
    <p><span class="left">&nbsp;&nbsp;&nbsp;运费</span><span class="right js_expressTotalPrice" data-express_price="0">0元</span></p>
    <p><span class="left">优惠券抵扣</span><span class="right js_couponSubPrice">0元</span></p>
    <p class="font-red"><span class="left">订单金额</span><span class="right"><em class="js_orderCountPrice" data-order_price="{$total_price_discount_format}">{$total_price_discount_format}</em>元</span></p>
    <div class="btns js_subOrder" id="baiduTjBtnPay"><a href="javascript:;">去结算</a></div>
  </div> *}


  <form action="{AnUrl('order/pay')}" id="js_orderForm" method="post">
    {if $is_direct_buy}
      <input type="hidden" name="sku_id" value="{$direct_sku_info.id}"/>
      <input type="hidden" name="num" value="{$direct_buy_num}"/>
    {/if}
    <input type="hidden" name="address"/>
    <input type="hidden" name="invoice_type"/>
    <input type="hidden" name="invoice_title"/>
    <input type="hidden" name="pay_type"/>
    <input type="hidden" name="coupon_code"/>
    <input type="hidden" name="express_id"/>
  </form>
</div>
<!--end submit-order-page-->
<script>
  $(function(){
    $('.submit-order-page .item dt').on('click', function(){
      $(this).parents('dl').find('dd').toggle();
      var icon = $(this).find('a');
      if (icon.hasClass('arrow-down')) {
        icon.removeClass('arrow-down').addClass('arrow-up');
      } else {
        icon.addClass('arrow-down').removeClass('arrow-up');
      }
    });

    $('.js_payTypeList dd').on('click', function(e){
      e.preventDefault();
      $(this).siblings().find('input').attr('checked', false);
      $(this).find('input').get(0).checked = true;

      var payType = $(this).data('pay_type');
      var paytitle = $(this).data('pay_title');
      $('.js_payTitle').html(paytitle+'支付');
      $('.js_payTypeList, .js_orderTradeGroup').data('pay_type', payType);
    });

    $('.js_invoiceList dd').on('click', function(e){
      e.preventDefault();
      $(this).siblings().find('input').attr('checked', false);
      $(this).find('input').get(0).checked = true;

      var invoiceType  = $(this).data('invoice_type');
      var invoiceTitle = $(this).data('invoice_title');
      $('.js_invoiceTitle').html(invoiceTitle);
      $('.js_invoiceList, .js_orderTradeGroup').data('invoice_type', invoiceType);
      console.log(invoiceType);
      if (invoiceType == 2) {
        $('.js_invoiceInfo').show();
        //$('.js_invoiceList, js_orderTradeGroup').data('invoice_title', $('.js_invoiceTitleInp').val());
      } else {
        $('.js_invoiceList, .js_orderTradeGroup').data('invoice_title', '');
        $('.js_invoiceInfo').hide();
      }
    });

    $('.js_expressTypeList dd').on('click', function(e){
      e.preventDefault();
      if ($(this).data('allow_slt') == 0) {
        return false;
      }
      var that  = $(this);
      var title = $(this).data('express_title');
      var id    = $(this).data('express_id');
      var price = $(this).data('express_price');
      var addressId = $('.js_orderTradeGroup').data('address_id');
      var url   = siteUrl+'/express/get_express_price';

      if (btnClick() == false) {
        return false;
      }
      $('.js_expressSltInfo').html('切换中...');
      $.get(url, { express_id:id, address_id:addressId }, function(json){
        if (json.info == 'ok') {
          $('.js_expressTitle').html(title);

          $('.js_expressTotalPrice').html(json.price+'.00元');
          $('.js_orderTradeGroup').data('express_error', '');
          $('.js_orderTradeGroup').data('express_price', json.price);
          $('.js_orderTradeGroup').data('express_id', id);
          $('.js_orderCountPrice').html(json.order_price);
          $('.js_expressSltInfo').html("运费："+json.price+'元');
        } else {
          location.href = location.href;
          //$('.js_orderTradeGroup').data('express_error', json.info);
        }
        btnClick('reset');
      }, 'json');

      that.siblings().find('input').attr('checked', false);
      that.find('input').get(0).checked = true;
    });
    
    $('.js_couponCode').on('blur', function(){
      var couponCode = $(this).val();
      var expressPrice = $('.js_expressTotalPrice').data('express_price');
      var goodsTotalPrice = $('.js_goodsTotalPrice').data('total_price');
      if (couponCode) {
        $('.js_viewCoupon').html(couponCode);
        //传入sku_id,num
        var sku_id = $('#js_orderForm input[name="sku_id"]').val();
        var num    = $('#js_orderForm input[name="num"]').val();
        var postdata = { coupon_code:couponCode, is_price:1, express_price:expressPrice };
        if(sku_id) {
          postdata.sku_id = sku_id;
          postdata.num    = num;
        }

        var url = siteUrl+'/coupon/check_coupon';
        $.post(url, postdata, function(json){
          if (json.info == 'ok') {
            $('.js_couponSubPrice').html('-'+json.price+'元');
            $('.js_orderCountPrice').html(json.order_price);
          } else {
            mobileShowMsg(json.info);
            $('.js_couponSubPrice').html('-0元');
            $('.js_orderCountPrice').html(goodsTotalPrice);
          }
        }, 'json');
      } else {
        $('.js_viewCoupon').html('暂无优惠卷');
        $('.js_couponSubPrice').html('-0元');
        $('.js_orderCountPrice').html(goodsTotalPrice);
      }
    });

    // 提交订单
    $('.js_subOrder').on('click', function(){
      var editAddress  = $('.js_orderTradeGroup').data('edit-address');
      var editPayType  = $('.js_orderTradeGroup').data('edit-paytype');
      var addressId    = $('.js_orderTradeGroup').data('address_id');
      var payType      = $(this).data('pay_type');
      var invoiceType  = $('.js_orderTradeGroup').data('invoice_type');
      var invoiceTitle = $.trim($('.js_invoiceTitleInp').val());
      var couponCode   = $('.js_couponCode').val();
      var expressId    = '';

      /*
      var expressId    = $('.js_orderTradeGroup').data('express_id');
      var expressError = $('.js_orderTradeGroup').data('express_error');

      if (expressError) {
        showMsg(expressError);
        return;
      }
      */
     
      /* if (couponCode) {
        var checkCouponUrl = siteUrl+'/coupon/check_coupon';
        $.post(checkCouponUrl, { coupon_code:couponCode, is_price:1 }, function(json){
          if (json.info == 'ok') {
            $('#js_orderForm').find('input[name=address]').val(addressId);
            $('#js_orderForm').find('input[name=invoice_type]').val(invoiceType);
            $('#js_orderForm').find('input[name=invoice_title]').val(invoiceTitle);
            $('#js_orderForm').find('input[name=coupon_code]').val(couponCode);
            $('#js_orderForm').find('input[name=pay_type]').val(payType);
            $('#js_orderForm').find('input[name=express_id]').val(expressId);

            $('#js_orderForm').submit();
          } else {
            $('.js_couponCode').val('');
            showMsg(json.info);
          }
        }, 'json');
        return;
      } */
      if (!addressId) {
        showMsg('请保存收获地址后，提交订单');
        return;
      }
      if(invoiceType == 2) {
        if(invoiceTitle == '') {
          showMsg('请您先填写发票抬头再进行付款。');
          return false;
        }
      }
      if (btnClick() == false) {
        return false;
      }
      $('#js_orderForm').find('input[name=address]').val(addressId);
      $('#js_orderForm').find('input[name=invoice_type]').val(invoiceType);
      $('#js_orderForm').find('input[name=invoice_title]').val(invoiceTitle);
      $('#js_orderForm').find('input[name=coupon_code]').val(couponCode);
      $('#js_orderForm').find('input[name=pay_type]').val(payType);
      $('#js_orderForm').find('input[name=express_id]').val(expressId);

      $('#js_orderForm').submit();
    });

    // getExpress();
  });

  // 计算运费
  function getExpress()
  {
    return false;
    var addressId = $('.js_orderTradeGroup').data('address_id');
    var url = siteUrl+'/express/get_express_price';
    var suerExpressId = $('.js_expressTypeList').data('express_id');

    $('.js_expressTypeList').find('input').attr('checked', false);
    $('.js_expressTypeList').find('dd').data('is_allow', 0);
    $('.js_expressTypeList').data('is_suer', 0);
    $('.js_expressTypeList').data('express_id', '');
    $('.js_expressTypeList').data('express_title', '');

    $('.js_expressTypeList dd').each(function(){
      var expressId = $(this).data('express_id');
      var that = $(this);
      var title = $(this).data('express_title');
      that.data('allow_slt', 1);
      $(this).find('.explain').html('运费计算中，请稍等');
      $.get(url, { express_id:expressId, address_id:addressId }, function(json){
        if (json.info == 'ok') {
          that.data('is_allow', 1);
          that.find('.explain').html('运费：'+json.price+'元');
          that.find('.explain').css({ color:'#737373' });
          that.find('span').css({ color:'#737373' });
          var isSure = $('.js_expressTypeList').data('is_suer');
          if (isSure == 0 || expressId == suerExpressId) {
            $('.js_expressTypeList').data('has_error', 1);
            if (expressId == suerExpressId) { //如果相同 先固定
              $('.js_expressTypeList').data('is_suer', 1);
              $('.js_expressTypeList').find('.curr').removeClass('curr');
              $('.js_expressTypeList').find('.checked').removeClass('checked');
            }

            that.find('input').get(0).checked = true;
            $('.js_expressTypeList').data('express_id', expressId);
            $('.js_expressTypeList').data('express_title', title);
            $('.js_expressTitle').html(title);

            $('.js_expressSltInfo').html("运费："+json.price+'元');
            $('.js_expressTotalPrice').html(json.price+'.00元');
            $('.js_orderTradeGroup').data('express_price', json.price);
            $('.js_orderTradeGroup').data('express_error', '');
            $('.js_orderTradeGroup').data('express_id', expressId);
            $('.js_orderCountPrice').html(json.order_price);
          }
        } else {
          var hasError = $('.js_expressTypeList').data('has_error');
          if (!hasError) {
            $('.js_orderTradeGroup').data('express_error', json.info);
            $('.js_expressSltInfo').html(json.info);
          }
          that.data('allow_slt', 0);
          that.find('.explain').html(json.info);
          that.find('.explain').css({ color:'#AAA' });
          that.find('span').css({ color:'#AAA' });
        }
      }, 'json');
    });
  }
</script>
<script language="JavaScript" type="text/javascript"><!--
/* You may give each page an identifying name, server, and channel on
the next lines. */
s.pageName="Nbd:购物流程:填写订单";
s.server=""
s.channel="Nbd"
s.pageType=""
s.prop1="Nbd:购物流程";
s.prop2="Nbd:购物流程:填写订单";
s.prop3="Nbd:购物流程:填写订单";
s.prop4="Nbd:购物流程:填写订单";
/* Conversion Variables */
s.campaign=""
s.state=""
s.zip=""
s.events="scCheckout";
s.purchaseID=""
s.eVar1=""
s.eVar2=""
s.eVar3=""
s.eVar4=""
s.eVar5=""
/************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/
var s_code=s.t();if(s_code)document.write(s_code)//--></script>
<script language="JavaScript" type="text/javascript"><!--
if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-')
//--></script><noscript><img src="http://lenovochina.122.2o7.net/b/ss/lenovo-nbd-prd/1/H.26.2--NS/0"
height="1" width="1" border="0" alt="" /></noscript><!--/DO NOT REMOVE/-->
<!-- End SiteCatalyst code version: H.26.2. -->
{include_core file="m/lib/footer.html"}